/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.personInfo;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import model.Constants;

/**
 * Contains information about origin of person.
 * @author Dmitri Paziy
 */
public class Origin implements Cloneable{
    private final Date birthDay;
    private final String place;

    /**
     * @param birthDay Birthday of a person
     * @param place place of birth of a person
     * @throws IllegalArgumentException if birthDay or place were specified
     * as <i>null</i>.
     */
    public Origin(Date birthDay, String place) {
        if (birthDay == null || place == null) {
            throw new IllegalArgumentException(Constants.NULL_ARGUMENT_MESSAGE);
        }
        this.birthDay = birthDay;
        this.place = place;
    }

    /**
     * Getter of birth day
     * @return birth day
     */
    public Date getBirthDay() {
        return (Date) birthDay.clone();
    }

    /**
     * Getter of place of birth
     * @return place of birth
     */
    public String getPlace() {
        return place;
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        
        builder.append("Date of birth: ");
        builder.append(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH).format(birthDay));
        builder.append(Constants.LINE_SEPARATOR);
        builder.append("Place of birth: ");
        builder.append(place);
        builder.append(Constants.LINE_SEPARATOR);
        
        return builder.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Origin other = (Origin) obj;
        if (this.birthDay != other.birthDay && (this.birthDay == null || !this.birthDay.equals(other.birthDay))) {
            return false;
        }
        if ((this.place == null) ? (other.place != null) : !this.place.equals(other.place)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 89 * hash + (this.birthDay != null ? this.birthDay.hashCode() : 0);
        hash = 89 * hash + (this.place != null ? this.place.hashCode() : 0);
        return hash;
    }

    @Override
    public Object clone() {
        return new Origin(birthDay, place);
    }
}
